package com.fs.base.command;

import java.util.List;

import lombok.Getter;
import lombok.Setter;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.fs.base.param.SysConstant;
import com.fs.base.pojo.Modle;
import com.fs.base.repository.ModleRepository;
import com.fs.base.service.RoleService;

/**
 * @author TiddlerCJ
 * @desc 加载模块数据
 */

@Component
@Order(value=2)
public class Command2 implements CommandLineRunner{
	private Logger log = Logger.getLogger(Command2.class); 
	@Autowired private ModleRepository modleRepository;
	
	/**
	 * 合规检查人
	 */
	@Getter @Setter @Value("${expense.node.user1}")
    private String users1;
	
	/**
	 * 浙江大区审核人
	 */
	@Getter @Setter @Value("${expense.node.user2}")
    private String users2;
	
	/**
	 * 财务审核人
	 */
	@Getter @Setter @Value("${expense.node.user3}")
    private String users3;
	
	/**
	 * 湖北大区审核人
	 */
	@Getter @Setter @Value("${expense.node.user4}")
    private String users4;
	
	/**
	 * 洪湖项目部大区审核人
	 */
	@Getter @Setter @Value("${expense.node.user5}")
    private String users5;
	
	@Autowired private RoleService roleService;
	public void run(String... args) throws Exception {
		//合规检查人
		SysConstant.USER_CONFIG_MAP.put("hg", users1);//张卓,杨芳
		//浙江大区审核人
		SysConstant.USER_CONFIG_MAP.put("zj", users2);//游斌
		//财务审核人
		SysConstant.USER_CONFIG_MAP.put("cw", users3);//田婵娟
		//湖北大区审核人
		SysConstant.USER_CONFIG_MAP.put("hb", users4);//余春华
		//洪湖项目部大区审核人
		SysConstant.USER_CONFIG_MAP.put("hh", users5);//朱英俊
		
		/*
		 * 加载Modle所有数据
		 */
		List<Modle> modleList = modleRepository.findAll(); 
		for(Modle m: modleList){
			SysConstant.MODLE_CLASSNAME.put(m.getModleName(), m.getClassName());
		}
		/*
		 * 加载用户id名称键值对
		 */
		roleService.loadUserIdNameMap();
		
		roleService.loadOrgNoNameMap();
		
		log.info(" Load ALL Data success! ");
	}
	
}
